<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="中文名称" prop="chineseName">
        <el-input
          v-model="queryParams.chineseName"
          placeholder="请输入中文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="英文名称" prop="englishName">
        <el-input
          v-model="queryParams.englishName"
          placeholder="请输入英文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="英文名称图谱" prop="englishNameKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.englishNameKg"-->
<!--          placeholder="请输入英文名称图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="国别" prop="nationality">-->
<!--        <el-input-->
<!--          v-model="queryParams.nationality"-->
<!--          placeholder="请输入国别"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="所属领域" prop="fieldOfAffiliation">-->
<!--        <el-input-->
<!--          v-model="queryParams.fieldOfAffiliation"-->
<!--          placeholder="请输入所属领域"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="隶属 (上下级机构)" prop="affiliation">-->
<!--        <el-input-->
<!--          v-model="queryParams.affiliation"-->
<!--          placeholder="请输入隶属 (上下级机构)"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="隶属(上下级机构)图谱" prop="affiliationKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.affiliationKg"-->
<!--          placeholder="请输入隶属(上下级机构)图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="机构工作性质" prop="natureOfWork">-->
<!--        <el-input-->
<!--          v-model="queryParams.natureOfWork"-->
<!--          placeholder="请输入机构工作性质"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="主官/领导人级别" prop="rankOfPrincipal">-->
<!--        <el-input-->
<!--          v-model="queryParams.rankOfPrincipal"-->
<!--          placeholder="请输入主官/领导人级别"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="主管/领导人图谱" prop="rankOfPrincipalKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.rankOfPrincipalKg"-->
<!--          placeholder="请输入主管/领导人图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="历任领导人-图谱" prop="formerLeadersKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.formerLeadersKg"-->
<!--          placeholder="请输入历任领导人-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="机构驻地" prop="headquarters">-->
<!--        <el-input-->
<!--          v-model="queryParams.headquarters"-->
<!--          placeholder="请输入机构驻地"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="机构驻地-图谱" prop="headquartersKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.headquartersKg"-->
<!--          placeholder="请输入机构驻地-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="人员规模" prop="staffSize">-->
<!--        <el-input-->
<!--          v-model="queryParams.staffSize"-->
<!--          placeholder="请输入人员规模"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="代表性成果-图谱" prop="representativeOutcomesKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.representativeOutcomesKg"-->
<!--          placeholder="请输入代表性成果-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:org:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:org:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:org:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orgList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键，自增" align="center" prop="id" />-->
      <el-table-column label="中文名称"  show-overflow-tooltip align="center" prop="chineseName" />
      <el-table-column label="中文名称-图谱"   show-overflow-tooltip align="center" prop="chineseNameKg" />
      <el-table-column label="英文名称"  show-overflow-tooltip  align="center" prop="englishName" />
      <el-table-column label="英文名称图谱"   show-overflow-tooltip  align="center" prop="englishNameKg" />
      <el-table-column label="国别"   show-overflow-tooltip  align="center" prop="nationality" />
      <el-table-column label="所属领域"   show-overflow-tooltip  align="center" prop="fieldOfAffiliation" />
      <el-table-column label="机构类型"   show-overflow-tooltip  align="center" prop="organizationType" />
      <el-table-column label="隶属 (上下级机构)"  show-overflow-tooltip  align="center" prop="affiliation" />
      <el-table-column label="隶属(上下级机构)图谱"   show-overflow-tooltip align="center" prop="affiliationKg" />
      <el-table-column label="机构工作性质"   show-overflow-tooltip  align="center" prop="natureOfWork" />
      <el-table-column label="主官/领导人级别"   show-overflow-tooltip  align="center" prop="rankOfPrincipal" />
      <el-table-column label="主管/领导人图谱"   show-overflow-tooltip  align="center" prop="rankOfPrincipalKg" />
      <el-table-column label="现任领导人"   show-overflow-tooltip  align="center" prop="currentLeader" />
      <el-table-column label="现任领导人-图谱"  show-overflow-tooltip  align="center" prop="currentLeaderKg" />
      <el-table-column label="历任领导人"    show-overflow-tooltip align="center" prop="formerLeaders" />
      <el-table-column label="历任领导人-图谱"   show-overflow-tooltip  align="center" prop="formerLeadersKg" />
      <el-table-column label="机构驻地"   show-overflow-tooltip  align="center" prop="headquarters" />
      <el-table-column label="机构驻地-图谱"   show-overflow-tooltip  align="center" prop="headquartersKg" />
      <el-table-column label="机构简介"   show-overflow-tooltip  align="center" prop="institutionProfile" />
      <el-table-column label="核心任务"  show-overflow-tooltip  align="center" prop="coreTasks" />
      <el-table-column label="主要职能"   show-overflow-tooltip align="center" prop="mainFunctions" />
      <el-table-column label="人员规模"  show-overflow-tooltip  align="center" prop="staffSize" />
      <el-table-column label="前身历史"  show-overflow-tooltip  align="center" prop="predecessorHistory" />
      <el-table-column label="代表性成果"   show-overflow-tooltip align="center" prop="representativeOutcomes" />
      <el-table-column label="代表性成果-图谱"   show-overflow-tooltip align="center" prop="representativeOutcomesKg" />
      <el-table-column label="关键词"   show-overflow-tooltip  align="center" prop="keywords" />
<!--      <el-table-column label="${comment}" align="center" prop="allInfo" />-->
      <el-table-column label="操作"  fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:org:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:org:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改力量建设-业务机构对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="中文名称" prop="chineseName">
          <el-input v-model="form.chineseName" placeholder="请输入中文名称" />
        </el-form-item>
        <el-form-item label="中文名称-图谱" prop="chineseNameKg">
          <el-input v-model="form.chineseNameKg" placeholder="请输入中文名称-图谱" />
        </el-form-item>
        <el-form-item label="英文名称" prop="englishName">
          <el-input v-model="form.englishName" placeholder="请输入英文名称" />
        </el-form-item>
        <el-form-item label="英文名称图谱" prop="englishNameKg">
          <el-input v-model="form.englishNameKg" placeholder="请输入英文名称图谱" />
        </el-form-item>
        <el-form-item label="国别" prop="nationality">
          <el-input v-model="form.nationality" placeholder="请输入国别" />
        </el-form-item>
        <el-form-item label="所属领域" prop="fieldOfAffiliation">
          <el-input v-model="form.fieldOfAffiliation" placeholder="请输入所属领域" />
        </el-form-item>
        <el-form-item label="隶属 (上下级机构)" prop="affiliation">
          <el-input v-model="form.affiliation" placeholder="请输入隶属 (上下级机构)" />
        </el-form-item>
        <el-form-item label="隶属(上下级机构)图谱" prop="affiliationKg">
          <el-input v-model="form.affiliationKg" placeholder="请输入隶属(上下级机构)图谱" />
        </el-form-item>
        <el-form-item label="机构工作性质" prop="natureOfWork">
          <el-input v-model="form.natureOfWork" placeholder="请输入机构工作性质" />
        </el-form-item>
        <el-form-item label="主官/领导人级别" prop="rankOfPrincipal">
          <el-input v-model="form.rankOfPrincipal" placeholder="请输入主官/领导人级别" />
        </el-form-item>
        <el-form-item label="主管/领导人图谱" prop="rankOfPrincipalKg">
          <el-input v-model="form.rankOfPrincipalKg" placeholder="请输入主管/领导人图谱" />
        </el-form-item>
        <el-form-item label="现任领导人" prop="currentLeader">
          <el-input v-model="form.currentLeader" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="现任领导人-图谱" prop="currentLeaderKg">
          <el-input v-model="form.currentLeaderKg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="历任领导人" prop="formerLeaders">
          <el-input v-model="form.formerLeaders" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="历任领导人-图谱" prop="formerLeadersKg">
          <el-input v-model="form.formerLeadersKg" placeholder="请输入历任领导人-图谱" />
        </el-form-item>
        <el-form-item label="机构驻地" prop="headquarters">
          <el-input v-model="form.headquarters" placeholder="请输入机构驻地" />
        </el-form-item>
        <el-form-item label="机构驻地-图谱" prop="headquartersKg">
          <el-input v-model="form.headquartersKg" placeholder="请输入机构驻地-图谱" />
        </el-form-item>
        <el-form-item label="机构简介" prop="institutionProfile">
          <el-input v-model="form.institutionProfile" type="textarea" placeholder="请输入机构简介" />
        </el-form-item>
        <el-form-item label="核心任务" prop="coreTasks">
          <el-input v-model="form.coreTasks" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="主要职能" prop="mainFunctions">
          <el-input v-model="form.mainFunctions" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="人员规模" prop="staffSize">
          <el-input v-model="form.staffSize" placeholder="请输入人员规模" />
        </el-form-item>
        <el-form-item label="前身历史" prop="predecessorHistory">
          <el-input v-model="form.predecessorHistory" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="代表性成果" prop="representativeOutcomes">
          <el-input v-model="form.representativeOutcomes" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="代表性成果-图谱" prop="representativeOutcomesKg">
          <el-input v-model="form.representativeOutcomesKg" placeholder="请输入代表性成果-图谱" />
        </el-form-item>
        <el-form-item label="关键词" prop="keywords">
          <el-input v-model="form.keywords" type="textarea" placeholder="请输入内容" />
        </el-form-item>
<!--        <el-form-item label="${comment}" prop="allInfo">-->
<!--          <el-input v-model="form.allInfo" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="图片" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'image'"
              :biz-type="'download'"
              :limit="1"
              style="margin-left: 20px"
              table-type="10"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="原文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz001'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="10"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="译文文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz002'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="10"
            ></FileUpload>
          </div>
        </el-form-item>

      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="精翻文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz003'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="10"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrg, getOrg, delOrg, addOrg, updateOrg } from "@/api/business/org";
import { guid } from '@/utils/utils'
import FileUpload from '@/components/fileUpload_neww.vue'
import Pictures from '@/components/Pictures'
export default {
  name: "Org",
  components: { Pictures,FileUpload },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 力量建设-业务机构表格数据
      orgList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        chineseName: null,
        chineseNameKg: null,
        englishName: null,
        englishNameKg: null,
        nationality: null,
        fieldOfAffiliation: null,
        organizationType: null,
        affiliation: null,
        affiliationKg: null,
        natureOfWork: null,
        rankOfPrincipal: null,
        rankOfPrincipalKg: null,
        currentLeader: null,
        currentLeaderKg: null,
        formerLeaders: null,
        formerLeadersKg: null,
        headquarters: null,
        headquartersKg: null,
        institutionProfile: null,
        coreTasks: null,
        mainFunctions: null,
        staffSize: null,
        predecessorHistory: null,
        representativeOutcomes: null,
        representativeOutcomesKg: null,
        keywords: null,
        allInfo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        chineseName: [
          { required: true, message: "中文名称不能为空", trigger: "blur" }
        ],
        englishName: [
          { required: true, message: "英文名称不能为空", trigger: "blur" }
        ],
        nationality: [
          { required: true, message: "国别不能为空", trigger: "blur" }
        ],
        fieldOfAffiliation: [
          { required: true, message: "所属领域不能为空", trigger: "blur" }
        ],
        organizationType: [
          { required: true, message: "机构类型不能为空", trigger: "change" }
        ],
        affiliation: [
          { required: true, message: "隶属 (上下级机构)不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询力量建设-业务机构列表 */
    getList() {
      this.loading = true;
      listOrg(this.queryParams).then(response => {
        this.orgList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        chineseName: null,
        chineseNameKg: null,
        englishName: null,
        englishNameKg: null,
        nationality: null,
        fieldOfAffiliation: null,
        organizationType: null,
        affiliation: null,
        affiliationKg: null,
        natureOfWork: null,
        rankOfPrincipal: null,
        rankOfPrincipalKg: null,
        currentLeader: null,
        currentLeaderKg: null,
        formerLeaders: null,
        formerLeadersKg: null,
        headquarters: null,
        headquartersKg: null,
        institutionProfile: null,
        coreTasks: null,
        mainFunctions: null,
        staffSize: null,
        predecessorHistory: null,
        representativeOutcomes: null,
        representativeOutcomesKg: null,
        keywords: null,
        allInfo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加力量建设-业务机构";
      let mizId = guid().replace(/-/g, '');
      this.form.id = mizId
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrg(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改力量建设-业务机构";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrg(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrg(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除力量建设-业务机构编号为"' + ids + '"的数据项？').then(function() {
        return delOrg(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/org/export', {
        ...this.queryParams
      }, `org_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
